<?php
class SinhviensController extends AppController {

	var $name = 'Sinhviens';

	function index($cd_id=null) {
		$this->Sinhvien->recursive = 0;
		$this->set('sinhviens', $this->paginate(array('chidoansv_id'=>$cd_id)));
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid sinhvien', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('sinhvien', $this->Sinhvien->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Sinhvien->create();
			if ($this->Sinhvien->save($this->data)) {
				$this->Session->setFlash(__('The sinhvien has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The sinhvien could not be saved. Please, try again.', true));
			}
		}
		$tongiaos = $this->Sinhvien->Tongiao->find('list');
		$phuongxas = $this->Sinhvien->Phuongxa->find('list');
		$dantocs = $this->Sinhvien->Dantoc->find('list');
		$chidoansvs = $this->Sinhvien->Chidoansv->find('list');
		$this->set(compact('tongiaos', 'phuongxas', 'dantocs', 'chidoansvs'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid sinhvien', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Sinhvien->save($this->data)) {
				$this->Session->setFlash(__('The sinhvien has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The sinhvien could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Sinhvien->read(null, $id);
		}
		$tongiaos = $this->Sinhvien->Tongiao->find('list');
		$phuongxas = $this->Sinhvien->Phuongxa->find('list');
		$dantocs = $this->Sinhvien->Dantoc->find('list');
		$chidoansvs = $this->Sinhvien->Chidoansv->find('list');
		$this->set(compact('tongiaos', 'phuongxas', 'dantocs', 'chidoansvs'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for sinhvien', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Sinhvien->delete($id)) {
			$this->Session->setFlash(__('Sinhvien deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Sinhvien was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
